package com.richard.base.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Window
import com.richard.base.R
import com.richard.base.util.ScreenUtil
import kotlinx.android.synthetic.main.base_dialog_confirm.*

/**
 ***************************************
 * 项目名称:Giggle
 * @Author wuzhiguo
 * 邮箱：wuzhiguo@ksjgs.com
 * 创建时间: 2020/11/12     4:03 PM
 * 用途:
 ***************************************
 */
class ConfirmDialog(
    context: Context,
    content: String,
    viewClick: OnViewClick?
) :
    Dialog(context, R.style.CommentDialog) {
    private val mContext: Context
    private var winW = 0
    private val viewClick: OnViewClick?
    private val content: String
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.base_dialog_confirm)
        initView()
        setSize()
    }

    override fun show() {
        super.show()
    }

    private fun initView() {
        if (!content.isNullOrEmpty()) {
            tv_content.text = content
        }
        tv_cancle.setOnClickListener {
            dismiss()
            viewClick?.onCancel()
        }
        tv_confirm.setOnClickListener {
            dismiss()
            viewClick?.onConfirm()
        }
    }

    fun setSize() {
//        winW = ScreenUtil.getScreenWidth(context)
//        val p = window!!.attributes
//        p.width = winW / 10 * 8
//        if (p.width > ScreenUtil.dpToPxInt(400)) {
//            p.width = ScreenUtil.dpToPxInt(400)
//        }
//        //        p.height = (int) (winW / 10 * 8 * 1.2);
//        window!!.attributes = p
        setCancelable(true)
    }

    interface OnViewClick {
        fun onConfirm()
        fun onCancel()
    }

    fun setCancelText(cancelText: String?) {
        tv_cancle!!.text = cancelText
    }

    fun setConfirmText(confirmText: String?) {
        tv_confirm!!.text = confirmText
    }

    /** @param context
     */
    init {
        mContext = context
        this.content = content
        this.viewClick = viewClick
        requestWindowFeature(Window.FEATURE_NO_TITLE)
    }
}